package com.ray.controller;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ray.exception.ServiceException;
import com.ray.service.MaterialSelectFilterService;
import com.ray.util.RequestUtil;
import com.ray.util.ResponseUtil;

/**
 * 物料筛选过滤
* <p>Title: MaterialSelectFilter</p>  
* <p>Description: </p>  
* @author 李斌  
* @date 2018年7月19日
 */
@Controller
@RequestMapping("/materialSelectFilter")
public class MaterialSelectFilterController {
	
	@Autowired
	MaterialSelectFilterService materialSelectFilterService;
	
	//装service名称的map
	private static Map<String,String> serviceMap;
	
	//初始化
	static {
		init();
	}
	
	private static void init() {
		serviceMap = new HashMap<String,String>();
		//未生成投料单页面
		serviceMap.put("1", "getOrderMaterialDataOnNotFeedOrder");
		//投料单查询
		serviceMap.put("2", "getFeedOrderMaterialDataOnNotIsBuild");
		//采购单查询
		serviceMap.put("3", "getPurchaseOrderMaterialData");
		//库存查询
		serviceMap.put("4", "getMaterialSumMoneyData");
		//出入库查询
		serviceMap.put("5", "getWarehouseInOutData");
		//生成采购单查询
		serviceMap.put("6", "getCreatePurchaseOrderData");
		//预采购查询
		serviceMap.put("7", "getAdvancePurchaseData");
		//发料单查询
		serviceMap.put("8", "getIssueNoteData");
		//可生成出库单查询
		serviceMap.put("9", "getFeedOrderMaterialData");
		//采购单未领完查询
		serviceMap.put("10", "getPurchaseOrderNotFinish");
		//入库结算查询
		serviceMap.put("11", "getWarehouseInSumMoneyData");
		//物料清单(未用)
		serviceMap.put("12", "getOrderInfoDetailBOM");
		//成品出库
		serviceMap.put("13", "getProductOutOrderData");
		//订单未投料的订单查询
		serviceMap.put("14", "getOrderInfoDetailByNotProduct");
		//订单备份信息
		serviceMap.put("15", "getDuplicateOrderData");
		//可生成退货单查询
		serviceMap.put("16", "getCreateReturnToProvderData");
		//已生成退货单
		serviceMap.put("17", "getQueryReturnToProviderData");
		//可生成退货入库单信息查询
		serviceMap.put("18", "createInCountToProviderData");
		//已生成退货入库单信息查询
		serviceMap.put("19", "queryInCountToProviderData");
		//可生成返料单查询
		serviceMap.put("20", "createReturnToWorkshopData");
		//生成返料单查询
		serviceMap.put("21", "getReturnToWorkshopData");
		//出库结算查询条件
		serviceMap.put("22", "outBalanceSelect");
		//车间需退回物料查询
		serviceMap.put("23", "workShopNeedReturnMaterial");
		//车间需退回物料查询
		serviceMap.put("24", "paymentRecordCustomerName");
		//员工日报表查询
		serviceMap.put("25", "queryEmployeeDailyWhere");
		//车间物料库存
		serviceMap.put("26", "workShopWarehouseMaterialWhere");
		//车间物料库存
		serviceMap.put("27", "getOrderMaterialStockCountWhere");
		//成品库存查询
		serviceMap.put("28", "finishStockSearch");
		//成品库存查询
		serviceMap.put("29", "changeOrderSelect");
		//qc查询条件
		serviceMap.put("30", "qcReportSelect");
		//qc看板查询条件
		serviceMap.put("31", "qcReportDisplaySelect");
		//预收付款记录查询条件
		serviceMap.put("32", "advancePaySelect");
		//招聘申请查询条件
		serviceMap.put("33", "getApplyRecruitSelect");
		
	}
	
	/**
	 * @throws InvocationTargetException 
	 * @throws IllegalArgumentException 
	 * @throws IllegalAccessException 
	 * @throws SecurityException 
	 * @throws NoSuchMethodException 
	 * 1 未生成投料单订单
	 * 2 投料单查询
	 * 3 采购单查询
	 * 统一获取物料筛选下来数据
	* @date 2018年7月19日 下午5:16:19 
	* @author 李斌
	* @return Map<String,Object> 
	* @throws
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/getMaterialSelectData")
	public Map<String,Object> getMaterialSelectData(HttpServletRequest request) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
		Map<String,Object> map = RequestUtil.getRequestAllParam(request);
		if(map.get("type")==null) {
			throw new ServiceException("参数为空异常");
		} 
		boolean  isExists =  serviceMap.containsKey(map.get("type"));
		if(!isExists) {
			return ResponseUtil.ResponseResult(null);
		}
		Method method = materialSelectFilterService.getClass().getMethod(serviceMap.get(map.get("type")), Map.class);
		Object obj = method.invoke(materialSelectFilterService, map);
		return ResponseUtil.ResponseResult(obj);
	}
}
